<template>
  <main>
    <van-field v-model="code" type="text" clearable label="邀请码" placeholder="请输入邀请码开通帐号" maxlength="32"/>
    <p class="tip"><span class="red">*</span>无邀请码的请联系管理员或客服，邀请码使用一次后失效。客服电话：13172263633</p>
    <van-button 
      class="new-btn"
      color="linear-gradient(to right, #FF9800, #FF5722)"
      @click="onSubmit"
      block>
      确认
    </van-button>
  </main>
</template>

<script>
import {mapGetters, mapActions} from 'vuex'
import { Dialog, Toast } from 'vant';
import * as Api from 'api'

export default {
  data() {
    return {
      code: '',
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  created() {
    this.$emit('showTabMenu', false);
  },
  methods: {
    ...mapActions([
      'GetUserInfo',
      'Token',
      'Set_activated'
    ]),
    onSubmit() {
      if (!this.code) {
        Toast('邀请码不能为空')
        return
      }
      Api.CheckActivated({code: this.code}).then(res => {
        if (res.status == 'success') {
          Toast('注册成功！')
          this.GetUserInfo()
          this.Set_activated('1')
          setTimeout(() => {
            this.$router.push({name: 'Personal'})
          }, 2000)
        } else {
          Toast('邀请码错误，请联系管理员，电话：13172263633')
        }
      }).catch(() => {})
    },
  }
}
</script>

<style scoped lang="less">
main{
  padding-top: 40px;
}
.new-btn{
  margin: 60px auto;
  width: 90%;
}
.tip{
  font-size: 14px;
  padding: 4px 15px;
  color: #888;
  .red{
    color: red;
  }
}
</style>
